﻿using System;
using CustomerList.Model;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Threading;
using MyMeetup.Helpers;

namespace MyMeetup.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class MySettingsViewModel : ViewModelBase
    {

       
        private INavigationService _navigationService;

        public RelayCommand ShowPrivacyCommand { get; private set; }

        /// <summary>
        /// Initializes a new instance of the Settings class.
        /// </summary>
        public MySettingsViewModel()
        {
            _navigationService = new NavigationService();
            ShowPrivacyCommand = new RelayCommand(GoToPrivacy);
        }



        public string ApplicationTitle { get { return "my meetup"; } }
        public string PageTitle { get { return "settings"; } }



        private void GoToPrivacy()
        {
            var ph = new PrivacyHelper();
            ph.Show();

        }

        /// <summary>
        /// The <see cref="UseLocationServices" /> property's name.
        /// </summary>
        public const string UseLocationServicesPropertyName = "UseLocationServices";

        private bool _useLocationServices;

        /// <summary>
        /// Gets the UseLocationServices property.
        /// TODO Update documentation:`
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool UseLocationServices
        {
            get
            {
                return App.Settings.UseLocServices;
            }

            set
            {
                if (App.Settings.UseLocServices == value)
                {
                    return;
                }

                var oldValue = _useLocationServices;
                App.Settings.UseLocServices = value;

              
                // Update bindings, no broadcast
                RaisePropertyChanged(UseLocationServicesPropertyName);

                // Update bindings and broadcast change using GalaSoft.MvvmLight.Messenging
                //RaisePropertyChanged(UseLocationServicesPropertyName, oldValue, value, true);
            }
        }


        /// <summary>
        /// The <see cref="SearchRadius" /> property's name.
        /// </summary>
        public const string SearchRadiusPropertyName = "SearchRadius";

        private int _searchRadius;

        /// <summary>
        /// Gets the SearchRadius property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public int SearchRadius
        {
            get
            {
                return App.Settings.SearchRadius;
            }

            set
            {
                if (App.Settings.SearchRadius == value)
                {
                    return;
                }

                var oldValue = _searchRadius;
                App.Settings.SearchRadius = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(SearchRadiusPropertyName);

                // Update bindings and broadcast change using GalaSoft.MvvmLight.Messenging
                //RaisePropertyChanged(SearchRadiusPropertyName, oldValue, value, true);
            }
        }

       
    }
}